;; Support muse
(setq load-path (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/muse"))

(require 'muse)          ; load generic module
(require 'muse-mode)     ; load authoring mode
(require 'muse-colors)   ; load coloring/font-lock module
(require 'muse-project)
;;(require 'muse-blosxom)  ; load blosxom module
(require 'muse-html)     ; load publishing styles I use
(require 'muse-wiki)
(require 'muse-latex)
(require 'muse-texinfo)

;; PATH
(setq base-dir "")
(setq server "www.linuxgraphics.cn/")
(setq pub-dir "~/work/web/trunk/")


(muse-derive-style "my-xhtml" "xhtml"
                   :header (concat pub-dir "public_html/muse/header")
                   :footer (concat pub-dir "public_html/muse/footer"))

(muse-derive-style "my-pdf" "pdf"
                   :header (concat pub-dir "public_html/muse/header.tex")
                   :footer (concat pub-dir "public_html/muse/footer.tex"))


;; Setup a project
(setq muse-project-alist
      '(
         ("News"  
           ("~/work/web/trunk/Pages/news" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/news")
	     )

	     ("Graphics"
           ("~/work/web/trunk/Pages/graphics" :default "index")
	       (:base "xhtml" 
            :path "~/work/web/trunk/public_html/graphics")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/proj")
	     )

         ("Window_manager"
           ("~/work/web/trunk/Pages/window_manager" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/window_manager")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/articles")
         )
	     ("Design Pattern"
           ("~/work/web/trunk/Pages/gui" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/gui")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/guoxue")
         )

	     ("Physics Engine"
           ("~/work/web/trunk/Pages/physics" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/physics")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/guoxue")
         )

	     ("Animation Engine"
           ("~/work/web/trunk/Pages/animation" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/animation")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/guoxue")
         )

	     ("Xwindow"
           ("~/work/web/trunk/Pages/xwindow" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/xwindow")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/guoxue")
         )
 
	     ("GTK"
           ("~/work/web/trunk/Pages/gtk" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/gtk")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("QT"
           ("~/work/web/trunk/Pages/qt" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/qt")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/qt")
         )

	     ("MiniGUI"
           ("~/work/web/trunk/Pages/minigui" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/minigui")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("DirectFB"
           ("~/work/web/trunk/Pages/directfb" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/directfb")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("Clutter"
           ("~/work/web/trunk/Pages/clutter" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/clutter")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("Android"
           ("~/work/web/trunk/Pages/android" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/android")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("PSP"
           ("~/work/web/trunk/Pages/psp" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/psp")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )


	     ("Home"
           ("~/work/web/trunk/Pages/home" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/home")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("UIShow"
           ("~/work/web/trunk/Pages/uishow" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/uishow")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("MaxOSX"
           ("~/work/web/trunk/Pages/macosx" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/macosx")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("FTK"
           ("~/work/web/trunk/Pages/ftk" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/ftk")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("BeagleBoard"
           ("~/work/web/trunk/Pages/beagle" :default "index")
           (:base "my-xhtml" 
            :path "~/work/web/trunk/public_html/beagle")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/blog")
         )

	     ("OpenGL"
           ("~/work/web/trunk/Pages/opengl" :default "index")
	       (:base "xhtml" 
            :path "~/work/web/trunk/public_html/opengl")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/proj")
	     )

	     ("OGRE"
           ("~/work/web/trunk/Pages/ogre" :default "index")
	       (:base "xhtml" 
            :path "~/work/web/trunk/public_html/ogre")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/proj")
	     )

	     ("QNX"
           ("~/work/web/trunk/Pages/qnx" :default "index")
	       (:base "xhtml" 
            :path "~/work/web/trunk/public_html/qnx")
;;           (:base "my-pdf" 
;;            :path "~/work/web/branches/dev-2-1/public_html/proj")
	     )


       )
)


;; Doc type
(setq muse-xhtml-doctype
"<?xml version=\"1.0 encoding=\"<lisp>(muse-html-encoding)</lisp> \"?>

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
)

;;Style sheet
(setq muse-html-style-sheet
      (concat
"<link
  rel=\"stylesheet\"
  type=\"text/css\"
  charset=\"utf-8\"
  media=\"all\"
  href=\"../css/site.css\"/>"))

;; Head section
(setq muse-xhtml-head
" <head>

    <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
    
    <link href=\"../rss/feed.rss\" type=\"application/rss+xml\" rel=\"alternate\" title=\"Sitewide RSS Feed\" />

    <meta name=\"generator\" content=\"muse.el\" />

    <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
  content=\"<lisp>muse-html-meta-content-type</lisp>\" />

    <lisp>
      (let ((maintainer (muse-style-element :maintainer)))
(when maintainer
  (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))
    </lisp>

    <lisp>muse-html-style-sheet</lisp>

  </head>"
)

;; Title
(setq muse-xhtml-headline "Liu Peng")

;; Menu
(defun muse-xhtml-menu (items)
  (concat "<div class=\"menu\"><div class=\"menuhead\">文章分类</div><div class=\"menubody\">"
  (mapconcat (function (lambda (x) (concat "<div class=\"menuitem\">\n"
   (cadr (cdr x))
 "<img src='../images/folderClose.gif' /> <a href=\"http://"
   server
   (cadr x)
   "\">\n"
   (car x)
   "</a>"
   "</div>")))
     items
     "\n"
     )
  "</div></div>"))

(setq muse-project-menu-list 
     `(("首页"     ,(concat base-dir "home/index.html") "")
       ("新闻"     ,(concat base-dir "news/index.html") "")
       ("Design Show"    ,(concat base-dir "uishow/index.html") "")
       ("设计模式"    ,(concat base-dir "gui/index.html") "")
       ("图形渲染"    ,(concat base-dir "graphics/index.html") "")
       ("物理引擎" ,(concat base-dir "physics/index.html") "")
       ("动画引擎" ,(concat base-dir "animation/index.html") "")
       ("窗口管理" ,(concat base-dir "window_manager/index.html") "")
       ("OpenGL开发"    ,(concat base-dir "opengl/index.html") "")
       ("OGRE"    ,(concat base-dir "ogre/index.html") "")
       ("X Window"    ,(concat base-dir "xwindow/index.html") "")
       ("GTK+"    ,(concat base-dir "gtk/index.html") "")
       ("QT"    ,(concat base-dir "qt/index.html") "")
       ("DirectFB"    ,(concat base-dir "directfb/index.html") "")
       ("MiniGUI"    ,(concat base-dir "minigui/index.html") "")
       ("Clutter"    ,(concat base-dir "clutter/index.html") "")
       ("Android"    ,(concat base-dir "android/index.html") "")
       ("PSP"    ,(concat base-dir "psp/index.html") "")
       ("Mac OS X"    ,(concat base-dir "macosx/index.html") "")
       ("FTK"    ,(concat base-dir "ftk/index.html") "")
       ("QNX"    ,(concat base-dir "qnx/index.html") "")
       ("BeagleBoard"    ,(concat base-dir "beagle/index.html") "")
       ("论坛"    ,(concat base-dir "bbs") "")
))


;;Back links
(defun muse-publish-backto (class base-dir)
  (let ((backto  (muse-publishing-directive "backto")))
    (when backto
      (let ((primary (split-string backto ","))
    backlink)
(dolist
    (secondary primary backlink)
  (setq tmp (split-string secondary "|"))
  (setq backlink
(concat backlink (concat "<div class='"
 class
 "'><img src='"
 base-dir
 "/images/list_item.gif' /> Back to <a href="
 (pop tmp)
 ".html>"
 (pop tmp)
 "</a></div>")
)
)
  )
backlink)))) 

;; Content listing
(defun muse-publish-content ()
  (let ((depths (muse-publishing-directive "contentdepth")))
    (when depths
      (let ((depth (string-to-number depths)))
(message "%S" (list depth))
(when (not (eq depth 0))
  (insert "<td class='contents'><div class='contenthead'>
                   Table of contents</div><div class='contentbody'>")
  (set (make-local-variable 'muse-publish-generate-contents)
       (cons (copy-marker (point) t) depth))
  (forward-char)
  (insert "</div></td>"))))))

;; Last changed
(defun format-time-last-changed ()
  (format-time-string "%Y-%m-%d [%H:%M]"))

(defun insert-last-changed ()
  (insert (format-time-last-changed)))

(defun update-last-changed ()
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward
"^#lastchange\\s +[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\s
 \\[[0-9]\\{2\\}:[0-9]\\{2\\}\\]"
nil t)
      (delete-region (match-beginning 0) (match-end 0))
      (insert "#lastchange ")
      (insert-last-changed))))

(defun record-last-changed ()
  (setq write-contents-hooks 'update-last-changed))

(setq muse-mode-hook (quote (auto-fill-mode flyspell-mode
                                            record-last-changed)))

;; License
(setq muse-xhtml-license
"<!-- Creative Commons-Lizenzvertrag -->
<div id=\"license\">
  <div id=\"licenseim\">
    <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/2.5/\">
      <img
      src=\"http://creativecommons.org/images/public/somerights20.png\"
      alt=\"Creative Commons-Lizenzvertrag\" border=\"0\" />
    </a>
  </div>
  <div id=\"licensetx\">
    The content of this site is licensed under a
    <a rel=\"license\"
    href=\"http://creativecommons.org/licenses/by-sa/2.5/\">
    Creative Commons 2.5 License</a> [attribution, share-alike]
  </div>
</div>
<!-- /Creative Commons-Lizenzvertrag -->

<!--

<rdf:RDF xmlns=\"http://web.resource.org/cc/\"
    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">
<Work rdf:about=\"\">
   <dc:title>after science</dc:title>
   <dc:date>2005</dc:date>
   <dc:description>a homepage</dc:description>
   <dc:creator><Agent>
      <dc:title>Gunnar Wrobel</dc:title>
   </Agent></dc:creator>
   <dc:rights><Agent>
      <dc:title>Gunnar Wrobel</dc:title>
   </Agent></dc:rights>
   <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/Text\" />
   <dc:source rdf:resource=\"http://gunnarwrobel.de/\"/>
   <license rdf:resource=\"http://creativecommons.org/licenses/by-sa/2.5/\" />
</Work>

<License rdf:about=\"http://creativecommons.org/licenses/by-sa/2.5/\">
   <permits rdf:resource=\"http://web.resource.org/cc/Reproduction\" />
   <permits rdf:resource=\"http://web.resource.org/cc/Distribution\" />
   <requires rdf:resource=\"http://web.resource.org/cc/Notice\" />
   <requires rdf:resource=\"http://web.resource.org/cc/Attribution\" />
   <permits rdf:resource=\"http://web.resource.org/cc/DerivativeWorks\" />
   <requires rdf:resource=\"http://web.resource.org/cc/ShareAlike\" />
</License>

</rdf:RDF>

-->"
)

;;header & footer
(setq muse-xhtml-header (concat pub-dir "public_html/muse/header"))
(setq muse-xhtml-footer (concat pub-dir "public_html/muse/footer"))

(defun funtest () "testing" (interactive) (message "Yay!") )

